package com.yihengyi.demo.test;

import org.springframework.http.HttpMethod;
import org.springframework.http.client.ClientHttpRequest;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.SimpleClientHttpRequestFactory;

import java.io.IOException;
import java.net.URI;

public class CustomClientHttpRequestFactory implements ClientHttpRequestFactory {

    // 你可以在这里添加自定义配置属性
    private final SimpleClientHttpRequestFactory delegate;

    public CustomClientHttpRequestFactory() {
        this.delegate = new SimpleClientHttpRequestFactory();
        // 配置delegate，例如设置超时
        this.delegate.setConnectTimeout(10000); // 连接超时时间
        this.delegate.setReadTimeout(10000);    // 读取超时时间
    }

    @Override
    public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
        // 使用delegate来创建ClientHttpRequest
        ClientHttpRequest request = delegate.createRequest(uri, httpMethod);

        // 在这里，你可以添加一些自定义逻辑，例如修改请求头

        return request;
    }

    // 你可以添加更多的自定义方法或配置方法
}
